<template >
    <van-list
        v-model:loading="loading"
        :finished="finished"
        finished-text="没有更多了"
        @load="onLoad"
        :immediate-check="false"
        >
        <!-- <van-cell v-for="(comment,index) in list" :key="index" :title="comment.aut_name" /> -->
        <!-- <comment-item v-for="(item, index) in list" :key="index" :comment="item" @reply-click="$emit('reply-click', $event)" /> -->
        <comment-item v-for="(item, index) in list" :key="index" :comment="item" @reply-click="$emit('reply-click', $event)" />
    </van-list>
</template>
<script>
import { getAllComments } from '@/apis/comment'
import CommentItem from '@/views/article/components/comment-item.vue'
export default {
    props: {
        articleId: {
            type:[Number, String, Object],
            required:true
        },
        list: {
            type: Array,
            default: () => []
        },
        type: {
            type: [String, Object],
            validator(value) {
                return ['a','c'].includes(value)
            },
            default: 'a'
        }
    },
    components: {
        CommentItem
    },
    created() {
        this.loading = true
        this.onLoad()
    },
    data() {
        return {
            loading:false,
            finished:false,
            offset:null,
            // list:[]
        }
    },
    methods: {
        async onLoad() {
            this.loading = true
            try {
                const {data} = await getAllComments({
                    type:this.type, //a 
                    source:this.articleId.toString(),
                    offset:this.offset,
                    limit:10
                })

                this.loading = false;
                console.log(data);
                const { results } = data.data
                this.list.push(...results)

                this.$emit('load-success',data.data)
                if (results.length) {
                    this.offset = data.data.last_id
                } else {
                    this.finished = true
                }
            } catch (error) {
                this.finished = true
                console.log(error);
            }
        },
        async replayAction (comment) {
            console.log('列表',comment);
            // const {data} = await getAllComments({
            //         type:'c',
            //         source:comment.com_id.toString(),
            //         offset:this.offset,
            //         limit:10
            //     })
            //     console.log(data);
        }
    }
}
</script>
<style lang="less" scoped>
    
</style>